package com.atguigu.userprofile.common.dao

import com.atguigu.userprofile.common.bean.TagInfo
import com.atguigu.userprofile.common.util.MysqlUtil

object TagInfoDAO {

  def getTagInfoByTaskId(taskId:String): TagInfo ={

    val sql=s"""
        |select id,tag_code,tag_name,
        |          parent_tag_id,tag_type,tag_value_type,
        |           tag_value_limit,tag_task_id,tag_comment,
        |           create_time
        | from tag_info where tag_task_id=${taskId}
        |""".stripMargin
    val maybeTagInfo: Option[TagInfo] = MysqlUtil.queryOne(sql, classOf[TagInfo], true)
    if(maybeTagInfo==None){
      null
    }else{
      maybeTagInfo.get
    }
  }

  //查询所有标签 ，潜在条件： 要取所有已启用的标签
  def  getTagInfoList(): List[TagInfo] ={
      val sql=
        s"""
           |select ti.* from tag_info  ti  join task_info tk on ti.tag_task_id =tk.id
           |where tk.task_status='1'
           |""".stripMargin

    val tagInfoList: List[TagInfo] = MysqlUtil.queryList(sql, classOf[TagInfo], true)
    tagInfoList
  }

}
